package com.monitor;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {

	/*
	 * public static void main(String[] args) throws IOException { String link =
	 * JOptionPane.showInputDialog("输入连接的ip和端口，以\":\"隔开"); int sr =
	 * link.lastIndexOf(':'); if (sr == -1) {
	 * JOptionPane.showMessageDialog(null, "请使用正确分隔符"); } String ip =
	 * link.substring(0, sr); String port = link.substring(sr + 1); Socket
	 * socket = null; try { socket = new Socket(ip, Integer.parseInt(port)); }
	 * catch (NumberFormatException e) { JOptionPane.showMessageDialog(null,
	 * "未知端口"); } catch (UnknownHostException e) {
	 * JOptionPane.showMessageDialog(null, "未知主机"); } catch (IOException e) {
	 * JOptionPane.showMessageDialog(null, "连接建立错误"); } DataInputStream in = new
	 * DataInputStream(socket.getInputStream()); final DataOutputStream out =
	 * new DataOutputStream(socket.getOutputStream()); final JFrame jf = new
	 * JFrame("java远程监控  "); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	 * double height = in.readDouble(); double width = in.readDouble();
	 * jf.setVisible(true); jf.setSize((int) width + 30, (int) height + 55);
	 * jf.enableInputMethods(false); Container con = jf.getContentPane(); final
	 * JPanel panel = new JPanel(); final JLabel screen = new JLabel();
	 * panel.add(screen); }
	 */
	public static void main(String[] args) {
		String host = "127.0.0.1";
		int port = 8919;
		try {
			Socket client = new Socket(host, port);
			Writer writer = new OutputStreamWriter(client.getOutputStream());
			writer.write("Hello From Client");
			writer.flush();
			writer.close();
			client.close();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
